this.BX=this.BX||{};this.BX.Landing=this.BX.Landing||{};(function(e,t,n){"use strict";class i extends n.Node{constructor(){super();this.escapeText=BX.Landing.Utils.escapeText;this.headerTagMatcher=BX.Landing.Utils.Matchers.headerTag;this.changeTagName=BX.Landing.Utils.changeTagName;this.textToPlaceholders=BX.Landing.Utils.textToPlaceholders;BX.Runtime.loadExtension("landing.node.text.tableeditor");BX.Landing.Block.Node.apply(this,arguments);this.type="text";this.tableBaseFontSize="22";this.onClick=this.onClick.bind(this);this.onPaste=this.onPaste.bind(this);this.onDrop=this.onDrop.bind(this);this.onInput=this.onInput.bind(this);this.onKeyDown=this.onKeyDown.bind(this);this.onMousedown=this.onMousedown.bind(this);this.onMouseup=this.onMouseup.bind(this);this.node.addEventListener("mousedown",this.onMousedown);this.node.addEventListener("click",this.onClick);this.node.addEventListener("paste",this.onPaste);this.node.addEventListener("drop",this.onDrop);this.node.addEventListener("input",this.onInput);this.node.addEventListener("keydown",this.onKeyDown);document.addEventListener("mouseup",this.onMouseup)}onAllowInlineEdit(){this.node.setAttribute("title",this.escapeText(BX.Landing.Loc.getMessage("LANDING_TITLE_OF_TEXT_NODE")))}onChange(e,t){this.superClass.onChange.call(this,arguments);if(!e){BX.Landing.UI.Panel.EditorPanel.getInstance().adjustPosition(this.node)}if(!t){BX.Landing.History.getInstance().push()}}onKeyDown(){if(event.code==="Backspace"){this.onBackspaceDown(event)}this.onInput(event)}onInput(e){clearTimeout(this.inputTimeout);var t=e.keyCode||e.which;if(!(t===90&&(top.window.navigator.userAgent.match(/win/i)?e.ctrlKey:e.metaKey))){this.inputTimeout=setTimeout(function(){if(this.lastValue!==this.getValue()){this.onChange(true);this.lastValue=this.getValue()}}.bind(this),400)}if(this.isTable(e)){var n=parseInt(window.getComputedStyle(e.srcElement).getPropertyValue("font-size"));if(e.srcElement.textContent===""&&e.srcElement.classList.contains("landing-table-td")&&n<this.tableBaseFontSize){e.srcElement.classList.add("landing-table-td-height")}else{e.srcElement.classList.remove("landing-table-td-height")}}}onEscapePress(){if(this.isEditable()){if(this===BX.Landing.Block.Node.Text.currentNode){BX.Landing.UI.Panel.EditorPanel.getInstance().hide()}this.disableEdit()}}onDrop(e){e.preventDefault()}onPaste(e){e.preventDefault();if(e.clipboardData&&e.clipboardData.getData){var t=e.clipboardData.getData("text/plain");var n=BX.Text.encode(t);var i=n.replace(new RegExp("\n","g"),"<br>");document.execCommand("insertHTML",false,i)}else{var a=window.clipboardData.getData("text");document.execCommand("paste",true,BX.Text.encode(a))}this.onChange()}onDocumentClick(e){if(this.isEditable()&&!this.fromNode){BX.Landing.UI.Panel.EditorPanel.getInstance().hide();this.disableEdit()}this.fromNode=false}onMousedown(e){if(!this.manifest.group){this.fromNode=true;if(this.manifest.allowInlineEdit!==false&&BX.Landing.Main.getInstance().isControlsEnabled()){e.stopPropagation();this.enableEdit();if(this.isTable(e)){this.disableEdit();BX.Landing.Block.Node.Text.currentNode.node.querySelectorAll(".landing-table-container").forEach((function(e){if(!e.hasAttribute("table-prepare")){BX.Landing.Block.Node.Text.prototype.prepareNewTable(e)}}));var t=parseInt(window.getComputedStyle(e.srcElement).getPropertyValue("font-size"));if(e.srcElement.textContent===""&&e.srcElement.classList.contains("landing-table-td")&&t<this.tableBaseFontSize){e.srcElement.classList.add("landing-table-td-height")}else{e.srcElement.classList.remove("landing-table-td-height")}}else{if(!this.manifest.textOnly&&!BX.Landing.UI.Panel.StylePanel.getInstance().isShown()){BX.Landing.UI.Panel.EditorPanel.getInstance().show(this.node,null,this.buttons)}if(BX.Landing.Block.Node.Text.nodeTableContainerList){BX.Landing.Block.Node.Text.nodeTableContainerList.forEach((function(e){e.tableEditor.unselect(e.tableEditor)}))}}BX.Landing.UI.Tool.ColorPicker.hideAll()}requestAnimationFrame((function(){if(e.target.nodeName==="A"||e.target.parentElement.nodeName==="A"){var t=document.createRange();t.selectNode(e.target);window.getSelection().removeAllRanges();window.getSelection().addRange(t)}}))}}onMouseup(){setTimeout(function(){this.fromNode=false}.bind(this),10)}onClick(e){if(this.isTable(e)){this.addTableButtons(e)}e.stopPropagation();e.preventDefault();this.fromNode=false;if(e.target.nodeName==="A"||e.target.parentElement.nodeName==="A"){var t=document.createRange();t.selectNode(e.target);window.getSelection().removeAllRanges();window.getSelection().addRange(t)}}isEditable(){return this.node.isContentEditable}enableEdit(){var e=BX.Landing.Block.Node.Text.currentNode;if(e){var t=BX.Landing.Block.Node.Text.currentNode.node;var n=t.querySelectorAll(".landing-table-container");if(n.length>0){n.forEach((function(e){if(!e.tableEditor){e.tableEditor=new BX.Landing.Node.Text.TableEditor.default(e)}}));BX.Landing.Block.Node.Text.nodeTableContainerList=n}}if(!this.isEditable()&&!BX.Landing.UI.Panel.StylePanel.getInstance().isShown()){if(this!==BX.Landing.Block.Node.Text.currentNode&&BX.Landing.Block.Node.Text.currentNode!==null){BX.Landing.Block.Node.Text.currentNode.disableEdit()}BX.Landing.Block.Node.Text.currentNode=this;this.buttons=[];this.buttons.push(this.getDesignButton());if(this.isHeader()){this.buttons.push(this.getChangeTagButton());this.getChangeTagButton().onChangeHandler=this.onChangeTag.bind(this)}this.lastValue=this.getValue();this.node.contentEditable=true;this.node.setAttribute("title","")}}getDesignButton(){if(!this.designButton){this.designButton=new BX.Landing.UI.Button.Design("design",{html:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_DESIGN"),attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_DESIGN")},onClick:function(){BX.Landing.UI.Panel.EditorPanel.getInstance().hide();this.disableEdit();this.onDesignShow(this.manifest.code)}.bind(this)})}return this.designButton}disableEdit(){if(this.isEditable()){this.node.contentEditable=false;if(this.lastValue!==this.getValue()){this.onChange();this.lastValue=this.getValue()}if(this.isAllowInlineEdit()){this.node.setAttribute("title",this.escapeText(BX.Landing.Loc.getMessage("LANDING_TITLE_OF_TEXT_NODE")))}}}getField(){if(!this.field){this.field=new BX.Landing.UI.Field.Text({selector:this.selector,title:this.manifest.name,content:this.node.innerHTML,textOnly:this.manifest.textOnly,bind:this.node});if(this.isHeader()){this.field.changeTagButton=this.getChangeTagButton()}}else{this.field.setValue(this.node.innerHTML);this.field.content=this.node.innerHTML}return this.field}setValue(e,t,n){this.preventSave(t);this.lastValue=this.isSavePrevented()?this.getValue():this.lastValue;this.node.innerHTML=e;this.onChange(false,n)}getValue(){if(this.node.querySelector(".landing-table-container")!==null){var e=this.node.cloneNode(true);this.prepareTable(e);return this.textToPlaceholders(e.innerHTML)}return this.textToPlaceholders(this.node.innerHTML)}isHeader(){return this.headerTagMatcher.test(this.node.nodeName)}isTable(e){var t=false;if(BX.Landing.Block.Node.Text.currentNode&&e){BX.Landing.Block.Node.Text.currentNode.node.querySelectorAll(".landing-table-container").forEach((function(n){if(n.contains(e.srcElement)){t=true}}))}return t}prepareNewTable(){table.querySelectorAll("br").forEach((function(e){e.remove()}));table.setAttribute("table-prepare","true");BX.Landing.Block.Node.Text.currentNode.onChange(true)}addTableButtons(e){var t=[];var n=[];var i=[];var a=this.getTableButtons();var s=[a[0],a[1],a[2],a[3]];var l=BX.Landing.Block.Node.Text.currentNode.node;var o=null;var d=false;var r=false;var c=false;var h=true;if(e.srcElement.classList.contains("landing-table")||e.srcElement.classList.contains("landing-table-col-dnd")){h=false}if(e.srcElement.classList.contains("landing-table-row-add")){r=true}if(e.srcElement.classList.contains("landing-table-col-add")){c=true}var g=[];var u=l.querySelectorAll(".landing-table");if(u.length>0){u.forEach((function(t){if(t.contains(e.srcElement)){o=t;return true}}))}a.forEach((function(t){t["options"]["srcElement"]=e.srcElement;t["options"]["node"]=l;t["options"]["table"]=o}));if(e.srcElement.classList.contains("landing-table-row-dnd")){i=e.srcElement.parentNode.children;i=Array.from(i);if(this.getAmountTableRows(o)>1){n=[0,1,2,3,4,5,6]}else{n=[0,1,2,3,4,5]}n.forEach((function(e){a[e]["options"]["target"]="row";a[e]["options"]["setTd"]=i;t.push(a[e])}))}if(e.srcElement.parentNode.classList.contains("landing-table-col-dnd")){var T=e.srcElement.parentElement.parentElement.childNodes;var L=Array.from(T);var f=[];L.forEach((function(e){if(e.nodeType===1){f.push(e)}}));var E=f.indexOf(e.srcElement.parentElement);var p=e.srcElement.parentElement.parentElement.parentElement.childNodes;p.forEach((function(e){if(e.nodeType===1){var t=[];e.childNodes.forEach((function(e){if(e.nodeType===1){t.push(e)}}));if(t[E]){i.push(t[E])}}}));if(this.getAmountTableCols(o)>1){n=[0,1,2,3,4,5,7]}else{n=[0,1,2,3,4,5]}n.forEach((function(e){a[e]["options"]["target"]="col";a[e]["options"]["setTd"]=i;t.push(a[e])}))}if(e.srcElement.classList.contains("landing-table-th-select-all")){var B;if(e.srcElement.classList.contains("landing-table-th-select-all-selected")){B=true;var p=e.srcElement.parentElement.parentElement.childNodes;p.forEach((function(e){e.childNodes.forEach((function(e){i.push(e)}))}));n=[0,1,2,3,4,5,8,9,10];n.forEach((function(e){a[e]["options"]["target"]="table";a[e]["options"]["setTd"]=i;t.push(a[e])}))}else{B=false;BX.Landing.UI.Panel.EditorPanel.getInstance().hide()}}if(e.srcElement.classList.contains("landing-table-td")){i.push(e.srcElement);n=[3,2,1,0];n.forEach((function(e){a[e]["options"]["target"]="cell";a[e]["options"]["setTd"]=i;a[e].insertAfter="strikeThrough";t.push(a[e])}));d=true;g=["justifyLeft","justifyCenter","justifyRight","justifyFull","createTable","pasteTable"]}var b;var N=[];i.forEach((function(e){if(e.nodeType===1){b=undefined;if(e.classList.contains("text-left")){b="alignLeft"}if(e.classList.contains("text-center")){b="alignCenter"}if(e.classList.contains("text-right")){b="alignRight"}if(e.classList.contains("text-justify")){b="alignJustify"}N.push(b)}}));var I=0;var m=true;while(I<N.length&&m){if(I>0){if(N[I]!==N[I-1]){m=false}}I++}if(m){b=N[0]}else{b=undefined}if(b){s.forEach((function(e){if(e.id===b){e.layout.classList.add("landing-ui-active")}}))}if(t[0]&&t[1]&&t[2]&&t[3]){t[0]["options"]["alignButtons"]=s;t[1]["options"]["alignButtons"]=s;t[2]["options"]["alignButtons"]=s;t[3]["options"]["alignButtons"]=s}if(!this.manifest.textOnly){if(h){if(!r&&!c&&o){if(!d){if(B===false){BX.Landing.UI.Panel.EditorPanel.getInstance().hide()}else{BX.Landing.UI.Panel.EditorPanel.getInstance().show(o.parentNode,null,t,true)}B=true}else{BX.Landing.UI.Panel.EditorPanel.getInstance().show(o.parentNode,null,t,true,g)}}}else{BX.Landing.UI.Panel.EditorPanel.getInstance().hide()}}}getChangeTagButton(){if(!this.changeTagButton){this.changeTagButton=new BX.Landing.UI.Button.ChangeTag("changeTag",{html:'<span class="landing-ui-icon-editor-'+this.node.nodeName.toLowerCase()+'"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_CHANGE_TAG")},onChange:this.onChangeTag.bind(this)})}this.changeTagButton.insertAfter="unlink";this.changeTagButton.activateItem(this.node.nodeName);return this.changeTagButton}getTableButtons(){this.buttons=[];this.buttons.push(new BX.Landing.UI.Button.AlignTable("alignLeft",{html:'<span class="landing-ui-icon-editor-left"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_ALIGN_LEFT")}}),new BX.Landing.UI.Button.AlignTable("alignCenter",{html:'<span class="landing-ui-icon-editor-center"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_ALIGN_CENTER")}}),new BX.Landing.UI.Button.AlignTable("alignRight",{html:'<span class="landing-ui-icon-editor-right"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_ALIGN_RIGHT")}}),new BX.Landing.UI.Button.AlignTable("alignJustify",{html:'<span class="landing-ui-icon-editor-justify"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_ALIGN_JUSTIFY")}}),new BX.Landing.UI.Button.ColorAction("tableTextColor",{text:BX.Landing.Loc.getMessage("EDITOR_ACTION_SET_FORE_COLOR"),attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_COLOR")}}),new BX.Landing.UI.Button.ColorAction("tableBgColor",{html:'<i class="landing-ui-icon-editor-fill-color"></i>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_TABLE_CELL_BG")}}),new BX.Landing.UI.Button.DeleteElementTable("deleteRow",{html:'<span class="landing-ui-icon-editor-delete"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_DELETE_ROW_TABLE")}}),new BX.Landing.UI.Button.DeleteElementTable("deleteCol",{html:'<span class="landing-ui-icon-editor-delete"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_DELETE_COL_TABLE")}}),new BX.Landing.UI.Button.StyleTable("styleTable",{html:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_TABLE_STYLE")+'<i class="fas fa-chevron-down g-ml-8"></i>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_TABLE_STYLE")}}),new BX.Landing.UI.Button.CopyTable("copyTable",{text:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_TABLE_COPY"),attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_TABLE_COPY")}}),new BX.Landing.UI.Button.DeleteTable("deleteTable",{html:'<span class="landing-ui-icon-editor-delete"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_TABLE_DELETE")}}));return this.buttons}onChangeTag(e){this.node=this.changeTagName(this.node,e);this.node.addEventListener("mousedown",this.onMousedown);this.node.addEventListener("click",this.onClick);this.node.addEventListener("paste",this.onPaste);this.node.addEventListener("drop",this.onDrop);this.node.addEventListener("input",this.onInput);this.node.addEventListener("keydown",this.onInput);if(!this.getField().isEditable()){this.disableEdit();this.enableEdit()}var t={};t[this.selector]=e;this.changeOptionsHandler(t)}getAmountTableCols(e){return e.querySelectorAll(".landing-table-col-dnd").length}getAmountTableRows(e){return e.querySelectorAll(".landing-table-row-dnd").length}prepareTable(e){var t=["table-selected-all","landing-table-th-select-all-selected","landing-table-cell-selected","landing-table-row-selected","landing-table-th-selected","landing-table-th-selected-cell","landing-table-th-selected-top","landing-table-th-selected-x","landing-table-tr-selected-left","landing-table-tr-selected-y","landing-table-col-selected","landing-table-tr-selected","table-selected-all-right","table-selected-all-bottom"];t.forEach((function(t){e.querySelectorAll("."+t).forEach((function(e){e.classList.remove(t)}))}));return e}onBackspaceDown(){var e=window.getSelection();var t=e.getRangeAt(0).startOffset;if(t===0){var n=e.focusNode;if(!BX.Type.isNil(n)&&n.nodeType!==3){if(n.firstChild.nodeType===3&&n.firstChild.firstChild.nodeType===3){n=n.firstChild.firstChild}else if(n.firstChild.nodeType!==3){n=n.firstChild}else{n=null}}if(n){var i=n.parentNode;var a=["BLOCKQUOTE","UL"];if(i&&a.includes(i.nodeName)){var s=document.createElement("div");s.append(n);i.append(s)}var l=n.parentNode.parentNode;while(l&&!a.includes(l.nodeName)){l=l.parentNode}if(l&&l.childNodes.length===1){l.after(n.parentNode);l.remove();event.preventDefault()}}}}}i.currentNode=[];e.Text=i})(this.BX.Landing.Node=this.BX.Landing.Node||{},BX,BX.Landing);
//# sourceMappingURL=text.bundle.map.js